package demo;

import java.util.Scanner;

public class stringSort {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println("请输入数字字符串：");
        String numString = s.nextLine();

        // 以空格切割字符串
        String[] numArray = numString.split(" ");

        int[] nums = new int[numArray.length];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Integer.parseInt(numArray[i]);
        }

        // 排序
        int temp = 0;
        for (int i = nums.length - 1; i >= 0; i--) {
            for (int j = 0; j < i; j++) {
                if(nums[j] > nums[j + 1]) {
                    temp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = temp;
                }
            }
        }

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < nums.length; i++) {
            if (i == nums.length - 1) {
                stringBuilder.append(nums[i]);
                break;
            }
            stringBuilder.append(nums[i] + " ");
        }
        System.out.println(stringBuilder.toString());
    }
}
